package a8;

public class NewtonRaphson {
	
	/**
	 * 
	 * @param a Parameter a be evaluated
	 * @param n Power of the root
	 */
	public NewtonRaphson(int a, int n) {
		this.n = n;
		this.a = a;
		moreGuess = true;
		x = 1;
	}
	/**
	 * 
	 * @return Next root approximation
	 */
	public double nextGuess() {
		if(Math.abs(x - Math.pow(a, 1.0/n)) <= 0.00001)
			moreGuess = false;
		
		x = x - ((Math.pow(x, n)-a)/(x*n));
		return x;
	}
	
	/**
	 * 
	 * @return The state of the approximation
	 */
	public boolean hasMoreGuesses() {
		return moreGuess;
	}
	
	private int a;
	private int n;
	private double x;
	private boolean moreGuess;
}
